home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Data / ConstData.cp next >
Text File  |  1997-06-28  |  2KB  |  90 lines

  1. // ConstData.cp
  2.  
  3. #ifndef ConstData_h
  4. #include "ConstData.h"
  5. #endif
  6. #ifndef MinMax_h
  7. #include "MinMax.h"
  8. #endif
  9.  
  10. bool ConstData::operator==( const ConstData& b ) const
  11.   {
  12.     if ( this->Length() != b.Length() )
  13.         return false;
  14.     
  15.     for ( uint32 i = 0; i < this->Length(); i++ )
  16.         if ( (*this)[i] != b[i] )
  17.             return false;
  18.     
  19.     return true;
  20.   }
  21.  
  22. bool ConstData::operator<( const ConstData& b ) const
  23.   {
  24.     uint32 matched = Min( this->Length(), b.Length() );
  25.     
  26.     for ( uint32 i = 0; i < matched; i++ )
  27.         if ( (*this)[i] < b[i] )
  28.             return true;
  29.     
  30.     return this->Length() < b.Length();
  31.   }
  32.  
  33. bool ConstData::operator<=( const ConstData& b ) const
  34.   {
  35.     uint32 matched = Min( this->Length(), b.Length() );
  36.     
  37.     for ( uint32 i = 0; i < matched; i++ )
  38.         if ( (*this)[i] > b[i] )
  39.             return false;
  40.     
  41.     return this->Length() <= b.Length();
  42.   }
  43.  
  44. bool ConstData::StartsWith( ConstData b ) const
  45.   {
  46.     if ( this->Length() < b.Length() )
  47.         return false;
  48.     
  49.     for ( uint32 i = 0; i < b.Length(); i++ )
  50.         if ( (*this)[i] != b[i] )
  51.             return false;
  52.     
  53.     return true;
  54.   }
  55.  
  56. bool ConstData::EndsWith( ConstData b ) const
  57.   {
  58.     if ( this->Length() < b.Length() )
  59.         return false;
  60.     
  61.     for ( uint32 i = 0; i < b.Length(); i++ )
  62.         if ( (*this)[ Length() - b.Length() + i ] != b[i] )
  63.             return false;
  64.     
  65.     return true;
  66.   }
  67.  
  68. int32 Compare( ConstData a, ConstData b )
  69.   {
  70.     uint32 matched = Min( a.Length(), b.Length() );
  71.     
  72.     for ( uint32 i = 0; i < matched; i++ )
  73.       {
  74.         int32 comparison = int32(a[i]) - int32(b[i]);
  75.         if ( comparison != 0 )
  76.             return comparison;
  77.       }
  78.     
  79.     if ( a.Length() < b.Length() )
  80.         return -1;
  81.     
  82.     if ( a.Length() > b.Length() )
  83.         return 1;
  84.     
  85.     return 0;
  86.   }
  87.  
  88. #include "ConstArrayOf.cp"
  89. template class ConstArrayOf<uint8>;
  90.